const rdata = require("../test/0809_3_frogman在雨林四排的多场地面移动路线.json");
const fs = require("fs-extra");
const path = require("path");

let simplefied = [];


let distanceFunc = (point1, point2) => {
  let disX = point1.x - point2.x;
  let disY = point1.y - point2.y;
  let distance = Math.pow(disX ** 2 + disY ** 2, 0.5);
  return distance;
}
for (let x of rdata) {
  // debugger
  let originLocations = x.locations;
  let simLocations = [];
  for (let i = 0; i < originLocations.length; i++) {
    if (simLocations.length == 0) {
      simLocations.push(originLocations[i])
    } else {
      let comp = simLocations[simLocations.length - 1];
      let nowPoint = originLocations[i];
      let dis = distanceFunc(nowPoint, comp);
      if (dis >= 10000) {
        simLocations.push(nowPoint);
      } else if (i == originLocations.length - 1) {
        simLocations.push(nowPoint);
      }
      // debugger
    }
  }
  simplefied.push({
    match_id: x.match_id,
    locations: simLocations
  });
  // console.log(x.match_id, originLocations.length, "==>", simLocations.length)
  // debugger
}
debugger
let trajectories = simplefied.filter(match => match.locations.length > 4).map(match => match.locations.map(e => {
  return {
    x: e.x,
    y: e.y
  }
}));

(async function () {
  await fs.writeFile(path.join("F:\\vscode-projects\\traclus_impl\\RAW_PUBG", `0913_TRACLUS_FROGMAN.json`), JSON.stringify({
    "epsilon": 40,
    "min_neighbors": 2,
    "min_num_trajectories_in_cluster": 3,
    "min_vertical_lines": 1,
    "min_prev_dist": 1,
    "trajectories": trajectories
  }));
  process.exit()
})();

debugger